﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DiscreteEventModel {

    public interface IDiscreteEventContext {
        void Initialize(DiscreteTime initialTime);
        void OnTimeStep(DiscreteTime previousTime, DiscreteTime nextTime);
    }

    public class EventTrace : IDiscreteEventContext {

        private double _traceLife;
        private Queue<DiscreteEvent> _eventTrace;

        public EventTrace(double traceLife) {
            this._traceLife = traceLife;
        }

        public void Initialize(DiscreteTime initialTime) {
            this._eventTrace = new Queue<DiscreteEvent>();
        }

        public void OnTimeStep(DiscreteTime previousTime, DiscreteTime nextTime) {
            while(this._eventTrace.Count > 0 && (nextTime - this._eventTrace.Peek().Time) > this._traceLife) {
                this._eventTrace.Dequeue();
            } 
        }
    }
}
